<?php

namespace app\upload\service;

use think\Controller;
use app\base\service\BaseService;
use app\upload\model\MarkdayPic as MarkdayPicModel;
use app\upload\model\ MarkdayBackgroundpic as MarkdayBGpicModel;


class UploadService extends Controller
{	
	// 上传单张纪念日图片
	protected function addMarkdayPic($file)
	{
		$base_obj = new BaseService();

		$res = $base_obj->upload_img($file);

		return $res;
	}

	// 插入纪念日图片记录
	protected function addMarkdayPicRow($param)
	{
		$param['createtime'] = time();
		$param['Isuse'] = 0;
		$param['Hits'] = 0;
		$param['picImg'] = $param['picImg'][0];

		$model = new MarkdayPicModel();

		$res = $model->insert($param);
		
		return $res;
	}

	// 插入纪念日背景图片记录
	protected function addMarkdayBGPicRow($param)
	{
		$param['createtime'] = time();
		$param['Isuse'] = 0;
		$param['HITS'] = 0;
		$param['backgroundpicImg'] = $param['backgroundpicImg'][0];

		$model = new MarkdayBGpicModel();

		$res = $model->insert($param);
		
		return $res;
	}

	// 获得纪念日图片
	protected function markdayPic($param)
	{
		if ('pic' == $param['type'])
		{
			$model = new MarkdayPicModel();

			$pics = $model->field('picid, picImg')->where('markdayid', $param['markdayid'])->select();
		}
		else
		{
			$model = new MarkdayBGpicModel();

			$pics = $model->field('backgroundpicid, backgroundpicImg')->where('markdayid', $param['markdayid'])->select();
		}

		return $pics;
	}
}